package org.dtrd.modules.archive.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.dtrd.modules.archive.entity.bean.report.DiabetesEducationReport;
import org.dtrd.modules.archive.entity.po.DtrdEntRdArchiveEducation;
import org.dtrd.modules.archive.mapper.DtrdEntRdEducationMapper;
import org.dtrd.modules.archive.service.IDtrdEntRdEducationService;
import org.dtrd.modules.system.service.ISysDictService;
import org.dtrd.common.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
@author 萧
@date 2021-10-01 22:47:26
**/
@Service
@DS("multi-datasource1")
public class DtrdEntRdEducationServiceImpl extends ServiceImpl<DtrdEntRdEducationMapper, DtrdEntRdArchiveEducation> implements IDtrdEntRdEducationService {

    @Autowired
    private ISysDictService dictService;

    private final static String pubDossierDiabetesKnowledge = "pubDossierDiabetesKnowledge";

    @Override
    public DiabetesEducationReport getPatientDiabetesEducationReport(Integer patientId) {
        DtrdEntRdArchiveEducation po = getOne(Wrappers.lambdaQuery(DtrdEntRdArchiveEducation.class)
                .eq(DtrdEntRdArchiveEducation::getPatientId, patientId));
        DiabetesEducationReport diabetesEducationReport = null;
        if (po != null) {
            diabetesEducationReport = new DiabetesEducationReport();
            // 接受过的糖尿病教育类型
            String received = po.getReceived();
            if (StrUtil.isNotBlank(received)) {
                String receive = dictService.translateCombineDict(received,  pubDossierDiabetesKnowledge, po.getReceivedOther());
                diabetesEducationReport.setReceived(receive);
            }
            // 希望接受的糖尿病教育类型
            String hope = po.getHope();
            if (StrUtil.isNotBlank(hope)) {
                String value = dictService.translateCombineDict(hope, pubDossierDiabetesKnowledge, po.getHopeOther());
                diabetesEducationReport.setHope(value);
            }

        }
        return diabetesEducationReport;
    }
}
